home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_server_focus.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  8.9 KB  |  403 lines

  1. unit ntc_server_focus;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     Buttons,
  36.     StdCtrls,
  37.     ExtCtrls,
  38.     inifiles,
  39.  
  40.     ntc_server_form;
  41.  
  42. const
  43.     default_timeout=500;
  44.     default_max_timeout=1500;
  45.     default_min_timeout=10;
  46.  
  47. type
  48.     Tscope_focus = class(tform)
  49.         focus_panel: TPanel;
  50.         focus_minus_button: TSpeedButton;
  51.         focus_plus_button: TSpeedButton;
  52.         speed_label: TLabel;
  53.         speed_box: TPanel;
  54.         first_speed_button: TSpeedButton;
  55.         timeout_duration_label: TLabel;
  56.         millisecond_label: TLabel;
  57.         timeout_duration_edit: TEdit;
  58.         stop_button: TSpeedButton;
  59.         focus_timer: TTimer;
  60.         max_timeout_label: TLabel;
  61.         max_timeout_edit: TEdit;
  62.         min_timeout_edit: TEdit;
  63.         min_timeout_label: TLabel;
  64.  
  65.         { form functions }
  66.         procedure formcreate(
  67.             Sender:TObject);
  68.  
  69.         procedure form_close_query(
  70.                     Sender: TObject;
  71.             var CanClose: Boolean);
  72.  
  73.         procedure flip_buttons(
  74.             toggle:boolean);
  75.  
  76.         { communications }
  77.         function send_message_check(
  78.             m:string)
  79.             :response_type;
  80.  
  81.         { configuration }
  82.         procedure load_settings;
  83.  
  84.         procedure save_settings;
  85.  
  86.         { events }
  87.         procedure FormShow(
  88.             Sender: TObject);
  89.  
  90.         procedure adjust;
  91.  
  92.         procedure check_activate(
  93.             Sender: TObject);
  94.  
  95.         procedure speed_button_click(
  96.             Sender: TObject);
  97.  
  98.         procedure stop_buttonClick(
  99.             Sender: TObject);
  100.  
  101.         procedure focus_minus_buttonClick(
  102.             Sender: TObject);
  103.  
  104.         procedure focus_plus_buttonClick(
  105.             Sender: TObject);
  106.  
  107.         procedure enable_focus_timer;
  108.  
  109.         procedure focus_timerTimer(
  110.             Sender: TObject);
  111.  
  112.         procedure timeout_duration_editChange(
  113.             Sender: TObject);
  114.  
  115.         procedure max_timeout_editChange(
  116.             Sender: TObject);
  117.  
  118.         procedure min_timeout_editChange(
  119.             Sender: TObject);
  120.  
  121.     private
  122.         { Private declarations }
  123.         speed_group_index:integer;
  124.     public
  125.         { Public declarations }
  126.         min_timeout,
  127.         max_timeout:integer;
  128.         focus_speeds,
  129.         start_focus_speed:integer;
  130.         can_focus:boolean;
  131.         focus_timeout:integer;
  132.         { configuration }
  133.         dimensions:dimensions_record;
  134.  
  135.         { events }
  136.         procedure check_visible_and_show_hide(
  137.             sender:tobject);
  138.             
  139.         procedure hide_form;
  140.         procedure show_form;
  141.     end;
  142.  
  143. var
  144.     scope_focus: Tscope_focus;
  145.  
  146. implementation
  147.  
  148. uses
  149.     ntc_server_network,
  150.     ntc_server_control,
  151.     ntc_server_config,
  152.     ntc_server_comms;
  153.  
  154. {$R *.dfm}
  155.  
  156.     { --------------
  157.         form functions
  158.         -------------- }
  159.  
  160. procedure Tscope_focus.formcreate(
  161.     Sender:TObject);
  162. begin
  163.     speed_group_index:=1;
  164.     can_focus:=false;
  165.     flip_buttons(false);
  166.     load_settings;
  167. end;
  168.  
  169. procedure tscope_focus.form_close_query(
  170.             Sender: TObject;
  171.     var CanClose: Boolean);
  172. begin
  173.     canclose:=false;
  174.     visible:=false;
  175.     with dimensions do
  176.         begin
  177.             form_top:=top;
  178.             form_left:=left;
  179.         end;
  180. end;
  181.  
  182.     { ---------
  183.         utilities
  184.         --------- }
  185.  
  186. function tscope_focus.send_message_check(
  187.     m:string)
  188.     :response_type;
  189. begin
  190.     result:=scope_network.send_message_check(m);
  191. end;
  192.  
  193. procedure Tscope_focus.flip_buttons(
  194.     toggle:boolean);
  195. begin
  196.     if scope_config.scope_type=celestron_type then
  197.         toggle:=false;
  198.     millisecond_label.enabled:=toggle;
  199.     focus_minus_button.enabled:=toggle;
  200.     focus_plus_button.enabled:=toggle;
  201.     timeout_duration_edit.enabled:=toggle;
  202.     speed_label.enabled:=toggle;
  203.     speed_box.enabled:=toggle;
  204.     first_speed_button.enabled:=toggle;
  205.     stop_button.enabled:=toggle;
  206. end;
  207.  
  208.     { -------------
  209.         focus control
  210.         ------------- }
  211.  
  212. procedure Tscope_focus.stop_buttonClick(
  213.     Sender: TObject);
  214. begin
  215.     send_message_check('stop_focus');
  216.     focus_timer.enabled:=false;
  217. end;
  218.  
  219.     { -------------
  220.         configuration
  221.         ------------- }
  222.  
  223. procedure tscope_focus.load_settings;
  224. begin
  225.     ini_file:=tinifile.create(application_path+'server.ini');
  226.     with ini_file do
  227.         begin
  228.             can_focus:=ReadBool('focus','can_focus',false);
  229.             focus_timeout:=readinteger('focus','timeout',default_timeout);
  230.             timeout_duration_edit.text:=inttostr(focus_timeout);
  231.             start_focus_speed:=readinteger('focus','start_focus_speed',1);
  232.             focus_speeds:=readinteger('focus','focus_speeds',2);
  233.             if (focus_speeds>9) or
  234.                  (focus_speeds<2) then
  235.                 focus_speeds:=2;
  236.             min_timeout:=readinteger('focus','min',default_min_timeout);
  237.             max_timeout:=readinteger('focus','max',default_max_timeout);
  238.             { form }
  239.             scope.get_dimensions(scope_focus,@dimensions,'focus',ini_file);
  240.             left:=dimensions.form_left;
  241.             top:=dimensions.form_top;
  242.             visible:=readbool('focus','visible',false);
  243.         end;
  244.     ini_file.free;
  245. end;
  246.  
  247. procedure tscope_focus.save_settings;
  248. begin
  249.     with ini_file do
  250.         begin
  251.             writeBool('focus','can_focus',can_focus);
  252.             writeinteger('focus','timeout',focus_timeout);
  253.             writeinteger('focus','start_focus_speed',start_focus_speed);
  254.             writeinteger('focus','focus_speeds',focus_speeds);
  255.             writeinteger('focus','min',min_timeout);
  256.             writeinteger('focus','max',max_timeout);
  257.             { form }
  258.             scope.find_vdu(scope_focus,@dimensions);
  259.             scope.write_dimensions(@dimensions,left,top,'focus',ini_file);
  260.             writebool('focus','visible',visible);
  261.         end;
  262. end;
  263.  
  264.     { ------
  265.         events
  266.         ------ }
  267.  
  268. procedure Tscope_focus.FormShow(
  269.     Sender: TObject);
  270. begin
  271.     with dimensions do
  272.         begin
  273.             top:=form_top;
  274.             left:=form_left;
  275.         end;
  276.     scope_control.update_speed_group(
  277.         speed_box,
  278.         first_speed_button,
  279.         start_focus_speed,
  280.         focus_speeds,
  281.         speed_button_click,
  282.         can_focus);
  283. end;
  284.  
  285. procedure tscope_focus.adjust;
  286. begin
  287.     with dimensions do
  288.         begin
  289.             form_top:=trunc(form_top/last_screen_height*current_height);
  290.             form_left:=trunc(form_left/last_screen_width*current_width);
  291.         end;
  292.     if visible then
  293.         show;
  294. end;
  295.  
  296. procedure tscope_focus.check_visible_and_show_hide(
  297.     sender:tobject);
  298. begin
  299.     if visible then
  300.         hide_form
  301.     else
  302.         show_form;
  303.     scope.show_hide(sender,visible);
  304. end;
  305.  
  306. procedure tscope_focus.hide_form;
  307. begin
  308.     with dimensions do
  309.         begin
  310.             form_top:=top;
  311.             form_left:=left;
  312.         end;
  313.     Visible:=false;
  314. end;
  315.  
  316. procedure tscope_focus.show_form;
  317. begin
  318.     Visible:=true;
  319. end;
  320.  
  321. procedure Tscope_focus.check_activate(
  322.     Sender: TObject);
  323. begin
  324.     scope.form_activate(scope_focus,@dimensions);
  325. end;
  326.  
  327. procedure Tscope_focus.speed_button_click(
  328.     Sender: TObject);
  329. begin
  330.     speed_group_index:=scope_control.set_slew_speed(speed_box);
  331. end;
  332.  
  333. procedure Tscope_focus.focus_minus_buttonClick(
  334.     Sender: TObject);
  335. begin
  336.     with scope_config do
  337.          if (scope_type=autostar_type) or (scope_type=lx200_type) then
  338.         send_message_check('focus(speed='+inttostr(speed_group_index)+
  339.             ',dir=-,timeout='+inttostr(focus_timeout)+')');
  340. end;
  341.  
  342. procedure Tscope_focus.focus_plus_buttonClick(
  343.     Sender: TObject);
  344. begin
  345.     with scope_config do
  346.          if (scope_type=autostar_type) or (scope_type=lx200_type) then
  347.         send_message_check('focus(speed='+inttostr(speed_group_index)+
  348.             ',dir=+,timeout='+inttostr(focus_timeout)+')');
  349. end;
  350.  
  351. procedure tscope_focus.enable_focus_timer;
  352. begin
  353.     focus_timer.interval:=focus_timeout;
  354.     focus_timer.enabled:=true;
  355. end;
  356.  
  357. procedure Tscope_focus.focus_timerTimer(
  358.     Sender: TObject);
  359. begin
  360.     focus_timer.enabled:=false;
  361.     if not (send_message_check('stop_focus')>=[exit_ok]) then
  362.         begin
  363.             scope_control.write_status_log('Unable to stop focus');
  364.             focus_timer.interval:=focus_timeout;
  365.             focus_timer.enabled:=true;
  366.         end;
  367. end;
  368.  
  369. procedure Tscope_focus.timeout_duration_editChange(
  370.     Sender: TObject);
  371. begin
  372.     focus_timeout:=strtointdef(timeout_duration_edit.text,default_timeout);
  373.     if (focus_timeout<min_timeout) or (focus_timeout>max_timeout) then
  374.         begin
  375.             focus_timeout:=default_timeout;
  376.             timeout_duration_edit.text:=inttostr(focus_timeout);
  377.         end;
  378. end;
  379.  
  380. procedure Tscope_focus.max_timeout_editChange(
  381.     Sender: TObject);
  382. begin
  383.     max_timeout:=strtointdef(max_timeout_edit.text,-1);
  384.     if (max_timeout<0) or (max_timeout>default_max_timeout) then
  385.         begin
  386.             max_timeout:=default_max_timeout;
  387.             max_timeout_edit.text:=inttostr(max_timeout);
  388.         end;
  389. end;
  390.  
  391. procedure Tscope_focus.min_timeout_editChange(
  392.     Sender: TObject);
  393. begin
  394.     min_timeout:=strtointdef(min_timeout_edit.text,-1);
  395.     if (min_timeout<0) or (min_timeout<default_min_timeout) then
  396.         begin
  397.             min_timeout:=default_min_timeout;
  398.             min_timeout_edit.text:=inttostr(min_timeout);
  399.         end;
  400. end;
  401.  
  402. end.
  403.